import React from 'react'
import { Redirect, Route } from 'react-router'
import { getToken } from 'utils/storage'

export default function AuthRoute({ path, component: Com, ...rest }) {
    return (
        <Route
            {...rest}
            path={path}
            render={props => {
                if (getToken()) {
                    return <Com {...props} />
                } else {
                    return <Redirect to={{ pathname: '/login', state: { form: props.location.pathname } }} />
                }
            }} />
    )
}
